tests/core: Assume C.UTF-8 if locale isn't found
authorAlex Kiernan <alex.kiernan@gmail.com>
Thu, 31 Oct 2019 11:28:07 +0000 (11:28 +0000)
committerAlex Kiernan <alex.kiernan@gmail.com>
Fri, 1 Nov 2019 05:05:53 +0000 (05:05 +0000)
When building with musl there's no locale command, also its default
locale is C.UTF-8, so just get C.UTF-8 if we can't find locale.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
tests/libtest-core.sh

index bc191332c9166d68cc3e4043630c1b4b9bafa4d0..46aafab03cc894d5a12dcbd80dbc87e0d2abf200 100644 (file)
@@ -37,9 +37,15 @@ assert_not_reached () {
 # Some tests look for specific English strings. Use a UTF-8 version
 # of the C (POSIX) locale if we have one, or fall back to en_US.UTF-8
 # (https://sourceware.org/glibc/wiki/Proposals/C.UTF-8)
-export LC_ALL=$(locale -a | grep -Ee '\.(UTF-8|utf8)' | grep -iEe '^(C|en_US)' | head -1 || true)
-if [ -z "${LC_ALL}" ]; then fatal "Can't find suitable UTF-8 locale"; fi
-
+#
+# If we can't find the locale command assume we have support for C.UTF-8
+# (e.g. musl based systems)
+if type -p locale >/dev/null; then
+    export LC_ALL=$(locale -a | grep -Ee '\.(UTF-8|utf8)' | grep -iEe '^(C|en_US)' | head -1 || true)
+    if [ -z "${LC_ALL}" ]; then fatal "Can't find suitable UTF-8 locale"; fi
+else
+    export LC_ALL=C.UTF-8
+fi
 # A GNU extension, used whenever LC_ALL is not C
 unset LANGUAGE